﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.IO;
using System.Web.Core;

namespace Yuanlin.Business
{
    public class CompanyRecruitAddControl : YuanlinUserControl
    {
        protected ValuedTextBox titleValuedTextBox;
        protected ValuedEditor descriptionValuedEditor;

        protected IButton SaveButton;
        protected IButton BackButton;
        private YuanlinUser user = HttpContext.Current.User as YuanlinUser;

        protected override void OnLoad(EventArgs e)
        {
            SaveButton.Click += new EventHandler(SaveButton_Click);
            BackButton.Click += new EventHandler(BackButton_Click);
        }

        public void BackButton_Click(object sender, EventArgs e)
        {
            PageRedirect();
        }

        public void SaveButton_Click(object sender, EventArgs e)
        {
            CompanyRecruit companyRecruit = new CompanyRecruit();
            
            companyRecruit.Title.Value =  CensorWordManager.CensorWord(this.titleValuedTextBox.Value);
            companyRecruit.Description.Value =  CensorWordManager.CensorWord(this.descriptionValuedEditor.Value);
            companyRecruit.UserId.Value = user.EntityId.Value;
            companyRecruit.CreateDate.Value = DateTime.Now;

            if (BusinessManager.CreateCompanyRecruit(companyRecruit) == -2)
            {
                Globals.ShowMessage(this.Page, "添加失败", "此信息已经存在！");
                return;
            }

            if (string.IsNullOrEmpty(user.CompanyRecruit))
            {
                user.CompanyRecruit = "1";
            }
            else
            {
                user.CompanyRecruit = (Int32.Parse(user.CompanyRecruit) + 1).ToString();
            }
           UserManager.UpdateUser(user);

           PageRedirect();
       }
        private void PageRedirect()
        {
            Page.Response.Redirect(SiteUrls.Instance().GetCompanyRecruitListUrl());
        }
    }
}